package com.toocms.jinjuhang.ui.index

import androidx.databinding.ObservableArrayList
import com.toocms.jinjuhang.config.Constants
import com.toocms.jinjuhang.data.index.NavsItemData
import com.toocms.jinjuhang.utils.RuleSkip
import com.toocms.tab.base.BaseViewModel
import com.toocms.tab.base.MultiItemViewModel
import com.toocms.tab.widget.navigation.FlipNavigationView
import com.toocms.tab.widget.navigation.NavigationItem

class IndexNavigationItemModel(viewModel: BaseViewModel<*>, items: List<NavsItemData>) :
    MultiItemViewModel<BaseViewModel<*>>(viewModel) {

    val items by lazy {
        val result = ObservableArrayList<NavigationItem>()
        items.forEach {
            result += NavigationItem().apply {
                icon = it.icon_path
                name = it.name
                target_rule = it.target_rule
                param = it.param
            }
        }
        result
    }

    val onItemClickListener = FlipNavigationView.OnItemClickListener {
        RuleSkip.skip(it.target_rule, it.param)
    }

    init {
        itemType = Constants.RecyclerViewItemType.ITEM_TYPE_TWO
    }
}